package com.huonan.jb.tools.yaml;

import cn.hutool.core.io.FileUtil;
import com.mz.social.wseg.springboot.starter.service.WordCloudService;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 比较源字段和yaml字段差异
 */
@Slf4j
public class Differs {

    private WordCloudService wordCloudService;
    public static void main(String[] args) {
        String fieldsPath = "/Users/lxp/IdeaProjects/Study/MainTest/data/field.txt";
        List<String> fieldsList = FileUtil.readUtf8Lines(fieldsPath);
        String yamlPath = "/Users/lxp/IdeaProjects/Study/MainTest/data/video-douyin.com-data.yaml";
        try {
            Map<String, Object>  yamlFileds = YamlHander.getMappings(yamlPath);
            Map<String, Object> yamlMappingFileds = (Map<String, Object>) yamlFileds.get("mappings");
            System.out.println(yamlMappingFileds.keySet().size());
            Map<String, Object> yamlMappingFormalFields = YamlHander.filter(yamlMappingFileds);
          //  System.out.println(yamlField.keySet().size());
            List<String> yamlNotHave =
                    fieldsList.stream().filter(f -> !yamlMappingFormalFields.containsKey(f)).collect(Collectors.toList());
            List<String> fieldsNotHave =
                    yamlMappingFileds.keySet().stream().filter(f -> !fieldsList.contains(f)).collect(Collectors.toList());
            log.info("fields:{},yaml:{},differ:{}", fieldsList.size(), yamlMappingFormalFields.size(), yamlNotHave.size());
            System.out.println("******新增******");
            yamlNotHave.forEach(System.out::println);
            System.out.println("******删除******");
            fieldsNotHave.forEach(System.out::println);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
